#!/usr/bin/python
# -*- coding: UTF-8 -*-

import tkinter
from tkinter import *
import tkinter.font as tkFont
import time
import pyHook
root = tkinter.Tk()
root.title('维修锁屏')
#——窗口配置
root.wm_attributes('-topmost',1)
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
root.geometry("600x100+%d+%d" %(w/2-330,h/2-70))
root.resizable(width=False, height=False)
#——锁屏前界面
labelenter1=Label(root, text='设置锁屏密码', font=('Arial', 14))
texte1 = StringVar()
e1 = tkinter.Entry(root, textvariable=texte1,font=('Arial', 14))
#——锁屏中界面
ft1=tkFont.Font(family='Fixdsys',size=int(h/6), weight=tkFont.BOLD)#Pyhon3字号只能为整数，Pyhon2.7时还可为浮点数，此处适配3改为整数
label0=Label(root, text='',height = 10)
label1=Label(root, text='维修中', font=ft1,)
label2=Label(root, text='请勿操作!', font=ft1)
label3=Label(root, text='输密码解锁',height = 2)
label4=Label(root, text='密码错误',height = 1)
ft2=tkFont.Font(family='Fixdsys', size=int(h/30), weight=tkFont.BOLD)
varKey=varAns=''
flag=1#锁屏前=1，锁屏后=2
#——退出锁屏
def quitroot():
    global varAns
    varAns = e1.get()
    print ('varKey:'+varKey)
    print ('varAns:'+varAns)
    if varAns==varKey :
        root.destroy()
    else:
        label4.pack()
bt1=Button(root,text='点击退出锁屏', font=ft2,command = quitroot)
#——进入锁屏
def enterroot():
    global flag
    flag=2
    print('开始锁屏')
    global varKey
    varKey=e1.get()
    print('开密码:' + varKey)
    root.geometry("%dx%d+0+0" %(w,h))
    label0.pack()
    label1.pack()
    label2.pack()
    label3.pack()
    texte1.set('')
    e1.pack_forget()
    e1.pack()
    e1.focus()
    bt1.pack()
    root.overrideredirect(True)
    bt2.pack_forget()
    labelenter1.pack_forget()
    localtime = time.localtime(time.time())
    #print time.strftime("%H:%M:%S", time.localtime()))
    global timesum
    timesum=time.time()
    label5time=Label(root, text='开始维修时间：'+time.strftime("%Y年%m月%d日 %H:%M:%S", time.localtime()),height = 1).pack()
#——回车事件
def enterpress(event):
    if flag==1:
        enterroot()
    else:
        quitroot()
#——强退事件
def protect():
    if flag==2:
        print('防强退')
    else:
        root.destroy()
root.bind('<Return>',enterpress)
bt2 = Button(root,text='确认锁屏',command= enterroot)
labelenter1.pack()
e1.pack()
e1.focus()
bt2.pack()
root.protocol("WM_DELETE_WINDOW", protect)
root.mainloop()
